package foodmaterial.excel;

import foodmaterial.utils.Constants;
import foodmaterial.utils.DateUtil;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Date;

public class EntityDefine {

    public static class EntityDesc {
        String setField;
        String getField;
        String desc ;
        int pos ;//在表格中列的位置
        boolean check ;
        Class<?> param;
        String defaultValue ;
        String formatter ;
        Method get ;
        Method set ;
        String[] booleanShow ;//把布尔类型的值显示成其它值

        public EntityDesc(String setField, String getField,String desc, int pos, boolean check,Class<?> param) {
            this.setField = setField;
            this.getField = getField;
            this.desc = desc;
            this.pos = pos;
            this.check = check;
            this.param = param ;
        }

        public EntityDesc(String setField, String getField,String desc, int pos, boolean check,Class<?> param,String[] booleanShow) {
            this.setField = setField;
            this.getField = getField;
            this.desc = desc;
            this.pos = pos;
            this.check = check;
            this.param = param ;
            this.booleanShow = booleanShow ;
        }

        public EntityDesc(String setField, String getField, String desc, int pos, boolean check, Class<?> param, String defaultValue) {
            this.setField = setField;
            this.getField = getField;
            this.desc = desc;
            this.pos = pos;
            this.check = check;
            this.param = param;
            this.defaultValue = defaultValue;
        }

        public EntityDesc(String setField, String getField, String desc, int pos, boolean check, Class<?> param, String defaultValue, String formatter) {
            this.setField = setField;
            this.getField = getField;
            this.desc = desc;
            this.pos = pos;
            this.check = check;
            this.param = param;
            this.defaultValue = defaultValue;
            this.formatter = formatter;
        }

        public String getSetField() {
            return setField;
        }

        public void setSetField(String setField) {
            this.setField = setField;
        }

        public String getGetField() {
            return getField;
        }

        public void setGetField(String getField) {
            this.getField = getField;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public int getPos() {
            return pos;
        }

        public void setPos(int pos) {
            this.pos = pos;
        }

        public boolean isCheck() {
            return check;
        }

        public void setCheck(boolean check) {
            this.check = check;
        }

        public Class<?> getParam() {
            return param;
        }

        public void setParam(Class<?> param) {
            this.param = param;
        }

        public String getDefaultValue() {
            return defaultValue;
        }

        public void setDefaultValue(String defaultValue) {
            this.defaultValue = defaultValue;
        }

        public String getFormatter() {
            return formatter;
        }

        public void setFormatter(String formatter) {
            this.formatter = formatter;
        }

        public Method getGet(Class<?> target) {
            if (get == null) {
                synchronized (this) {
                    if (get == null) {
                        try {
                            get = target.getDeclaredMethod("get" + getField, null);
                        } catch (NoSuchMethodException e) {
                            e.printStackTrace();
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            return get ;
        }

        public Method getSet(Class<?> target) {
            if (set == null) {
                synchronized (this) {
                    if (set == null) {
                        try {
                            set = target.getDeclaredMethod("set" + setField, param);
                        } catch (NoSuchMethodException e) {
                            e.printStackTrace();
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            return set ;
        }

        public Object executeFormatter(Object value) {
            if (formatter == null) return value;
            if (value instanceof Date) {
                return DateUtil.format((Date) value, formatter);
            } else if (value instanceof Double) {
                java.text.DecimalFormat df = new java.text.DecimalFormat(formatter);
                return df.format(value) ;
            } else if (value instanceof Boolean) {
                String[] temp = formatter.split(":");
                if (((Boolean)value)) return temp[0] ;
                else return temp[1] ;
            } else {
                return value ;
            }
        }

        public boolean isBoolean() {
            return (booleanShow == null) ? false : true ;
        }

        public String getBooleanShowValue(Object val) {
            Boolean val1 = (Boolean) val ;
            if (val1.booleanValue()) return booleanShow[0] ;
            else return booleanShow[1] ;
        }
    }

    public static EntityDesc[] CustomerDefine = {
            //new EntityDesc("Code","Code","客户编码",0,true,String.class),
            new EntityDesc("Name","Name","客户名称",0,true,String.class),
            new EntityDesc("Address","Address","客户地址",1,false,String.class),
            new EntityDesc("LiaisonMan","LiaisonMan","客户联系人",2,false,String.class),
            new EntityDesc("LiaisonTel","LiaisonTel","客户联系电话",3,false,String.class),
            new EntityDesc("AreaId","AreaName","区域",4,true,Long.class),
            new EntityDesc("RouterId","RouterName","线路",5,true,Long.class),
            new EntityDesc("AreaMasterName","AreaMasterName","区域主管",6,false,String.class),
            new EntityDesc("AreaMasterTel","AreaMasterTel","区域主管电话",7,false,String.class),
            new EntityDesc("Driver","Driver","配送司机",8,false,String.class),
            new EntityDesc("BusinessPeople","BusinessPeople","商务人员",9,false,String.class),
            new EntityDesc("SupplyTypeId","SupplyTypeName","配送类型",10,true,Long.class),
            new EntityDesc("SupplyTeamId","SupplyTeamName","配送小组",11,true,Long.class),
            new EntityDesc("CustomerType","CustomerType","客户类型",12,true,String.class),
            new EntityDesc("ShowOrder","ShowOrder","显示顺序",13,false,Integer.class)
    };

    public static EntityDesc[] FoodMaterialDefine = {
            new EntityDesc("TypeId","TypeName","食材分类",0,true,Long.class),
            new EntityDesc("Name","Name","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("RaxRate","RaxRate","税率",4,true,Double.class),
            new EntityDesc("UnitName","UnitName","计量单位",5,true,String.class),
            new EntityDesc("ExpressionUnit","ExpressionUnit","计算单位",6,true,Integer.class),
            new EntityDesc("SalePrice","SalePrice","销售价",7,true, BigDecimal.class),
            new EntityDesc("BuyPrice","BuyPrice","进货价",8,true,BigDecimal.class),
            new EntityDesc("Amount","Amount","库存",9,true,BigDecimal.class),
            new EntityDesc("Energy","Energy","能量",10,false,Double.class,"0"),
            new EntityDesc("Protein","Protein","蛋白质",11,false,Double.class,"0"),
            new EntityDesc("Fat","Fat","脂肪",12,false,Double.class,"0"),
            new EntityDesc("Carbohydrate","Carbohydrate","碳水化合物",13,false,Double.class,"0"),
            new EntityDesc("OriginalProcessRate","OriginalProcessRate","毛净转化率",14,false,Double.class,"100"),
            new EntityDesc("OriginalType","OriginalType","毛菜对照",15,true,Long.class,"0")
    };

    public static EntityDesc[] FoodMaterialSupplyDefine = {
            new EntityDesc("Name","Name","食材名称",0,true,String.class)
    };

    public static EntityDesc[] CustomerMealsDefine = {
            new EntityDesc("CustomerId","CustomerName","客户名称",0,true,Long.class),
            new EntityDesc("MealsTypeNameId","MealsTypeName","餐别",1,true,Long.class),
            new EntityDesc("MealStandard","MealStandard","餐标",2,true,BigDecimal.class),
            new EntityDesc("MealPersons","MealPersons","人数",3,true,Integer.class)
    };

    public static EntityDesc[] FoodMaterialDownloadDefine = {
            new EntityDesc("TypeId","TypeName","食材分类",0,true,Long.class),
            new EntityDesc("Name","Name","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("RaxRate","RaxRate","税率",4,true,Double.class),
            new EntityDesc("UnitId","UnitName","计量单位",5,true,Long.class),
            new EntityDesc("ExpressionUnit","ExpressionUnit","分配单位",6,true,Integer.class),
            new EntityDesc("SalePrice","SalePrice","销售价",7,true,BigDecimal.class),
            new EntityDesc("Energy","Energy","能量",8,false,Double.class,"0"),
            new EntityDesc("Protein","Protein","蛋白质",9,false,Double.class,"0"),
            new EntityDesc("Fat","Fat","脂肪",10,false,Double.class,"0"),
            new EntityDesc("Carbohydrate","Carbohydrate","碳水化合物",11,false,Double.class,"0")
    };

    public static EntityDesc[] ProcessFoodMaterialDownloadDefine = {
            new EntityDesc("TypeId","TypeName","食材分类",0,true,Long.class),
            new EntityDesc("Name","Name","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("RaxRate","RaxRate","税率",4,true,Double.class),
            new EntityDesc("UnitId","UnitName","计量单位",5,true,Long.class),
            new EntityDesc("ExpressionUnit","ExpressionUnit","分配单位",6,true,Integer.class),
            new EntityDesc("SalePrice","SalePrice","销售价",7,true,BigDecimal.class),
            new EntityDesc("Energy","Energy","能量",8,false,Double.class,"0"),
            new EntityDesc("Protein","Protein","蛋白质",9,false,Double.class,"0"),
            new EntityDesc("Fat","Fat","脂肪",10,false,Double.class,"0"),
            new EntityDesc("Carbohydrate","Carbohydrate","碳水化合物",11,false,Double.class,"0"),
            new EntityDesc("OriginalProcessRate","OriginalProcessRate","毛净转化率",12,false,Double.class,"0"),
            new EntityDesc("OriginalTypeName","OriginalTypeName","毛菜对照",13,false,String.class)
    };

    /**
     * 采购计划生成excel
     */
    public static EntityDesc[] PurchasePlanDefine = {
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",4,true,String.class),
            new EntityDesc("PlanAmount","PlanAmount","数量",5,true,Integer.class)
    };

    /**
     * 库存报损报溢汇总
     */
    public static EntityDesc[] ProfitAndLossDefine = {
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",4,true,String.class),
            new EntityDesc("Amount","Amount","数量",5,true,Integer.class)
    };

    /**
     * 采购对账
     */
    public static EntityDesc[] PurchaseCheckDefine = {
            new EntityDesc("Id","Id","单据号码",1,true,Long.class),
            new EntityDesc("PurchasePersonName","PurchasePersonName","采购人",2,true,String.class),
            new EntityDesc("PayStatus","PayStatus","支付状态",3,false,Boolean.class,null,"支付:未付"),
            new EntityDesc("PurchaseDate","PurchaseDate","采购日期",4,true, Date.class,null,"yyyy-MM-dd"),
            new EntityDesc("AmountOfMoney","AmountOfMoney","金额",5,true,Double.class,null,"#,###.##"),
            new EntityDesc("Remark","Remark","备注",6,false,String.class)
    };

    public static EntityDesc[] PurchaseSummaryDefine = {
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",4,true,String.class),
            new EntityDesc("Amount","Amount","数量",5,true,Integer.class)
    };

    public static EntityDesc[] FinancialPurchaseSummaryDefine = {
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",4,true,String.class),
            new EntityDesc("Amount","Amount","数量",5,true,Integer.class),
            new EntityDesc("Total","Total","金额",6,true,Double.class,null,"#,###.##")
    };

    //客户开票清单
    public static EntityDesc[] CustomerBillingDetailedListDefine = {
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材名称",1,true,String.class),
            new EntityDesc("OriginalProcess","OriginalProcess","",2,false,Boolean.class,new String[]{"净","毛"}),
            new EntityDesc("Specs","Specs","规格",3,false,String.class),
            new EntityDesc("Brand","Brand","品牌",4,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",5,true,String.class),
            new EntityDesc("RaxRate","RaxRate","税率",6,true,Double.class,null,"#,###.##"),
            new EntityDesc("TotalAmount","TotalAmount","数量",7,true,Integer.class),
            new EntityDesc("Total","Total","金额",8,true,Double.class,null,"#,###.##")
    };

    public static EntityDesc[] RecipeCustomerBillingDetailedListDefine = {
            new EntityDesc("RecipeTemplateName","RecipeTemplateName","名称",1,true,String.class),
            new EntityDesc("TotalAmount","TotalAmount","数量",2,true,Integer.class),
            new EntityDesc("Total","Total","金额",3,true,Double.class,null,"#,###.##")
    };

    //客户对账
    public static EntityDesc[] CustomerCheckDefine = {
            new EntityDesc("SupplyDate","SupplyDate","配送日期",1,true,Date.class,null, Constants.DEFAULT_DATE_FORMAT),
            new EntityDesc("Id","Id","单据编号",2,true,Long.class),
            new EntityDesc("MealsTypeName","MealsTypeName","餐别",3,false,String.class),
            new EntityDesc("AmountOfMoney","AmountOfMoney","金额",4,true,Double.class,null,"#,###.##"),
            new EntityDesc("Status","Status","订单状态",5,true,String.class)
    };

    //库存查询
    public static EntityDesc[] StockDefine = {
            new EntityDesc("TypeName","TypeName","分类",1,true,String.class),
            new EntityDesc("Name","Name","食材名称",2,true,String.class),
            new EntityDesc("Specs","Specs","规格",3,false,String.class),
            new EntityDesc("Brand","Brand","品牌",4,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",5,true,String.class),
            new EntityDesc("Amount","Amount","数量",6,true,Integer.class)
    };

    //财务销售汇总
    public static EntityDesc[] SaleSummaryDefine = {
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材名称",1,true,String.class),
            new EntityDesc("Specs","Specs","规格",2,false,String.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",4,true,String.class),
            new EntityDesc("TotalAmount","TotalAmount","数量",5,true,Integer.class),
            new EntityDesc("Total","Total","金额",6,true,Double.class,null,"#,###.##")
    };

    public static EntityDesc[] RecipeSaleSummaryDefine = {
            new EntityDesc("RecipeTemplateName","RecipeTemplateName","菜谱名称",1,true,String.class),
            new EntityDesc("TotalAmount","TotalAmount","数量",2,true,Integer.class),
            new EntityDesc("Total","Total","金额",3,true,Double.class,null,"#,###.##")
    };

    //客户供应商
    public static EntityDesc[] CustomerSupplierDefine = {
            new EntityDesc("CustomerId","CustomerName","客户",0,true,String.class),
            new EntityDesc("FoodMaterialId","FoodMaterialName","食材",1,true,String.class),
            new EntityDesc("SupplierId","SupplierName","供应商",2,true,String.class)
    };

    public static EntityDesc[] ProductionCapacityDefine = {
            new EntityDesc("ProcessName","ProcessName","净菜",1,false,String.class),
            new EntityDesc("ProcessAmount","ProcessAmount","净菜量",2,false,Integer.class),
            new EntityDesc("Brand","Brand","品牌",3,false,String.class),
            new EntityDesc("Specs","Specs","规格",4,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",5,false,String.class),
            new EntityDesc("OriginalName","OriginalName","毛菜",6,false,String.class),
            new EntityDesc("OriginalAmount","OriginalAmount","毛菜量",7,false,Integer.class),
            new EntityDesc("OriginalProcessRate","OriginalProcessRate","转化率%",8,false,Double.class)
    };

    public static EntityDesc[] ProcessPlanDefine = {
            new EntityDesc("ProcessName","ProcessName","净菜",1,false,String.class),
            new EntityDesc("Brand","Brand","品牌",2,false,String.class),
            new EntityDesc("Specs","Specs","规格",3,false,String.class),
            new EntityDesc("UnitName","UnitName","单位",4,false,String.class),
            new EntityDesc("ProcessAmount","ProcessAmount","计划量",5,false,Integer.class),
            new EntityDesc("OriginalName","OriginalName","毛菜",6,false,String.class)
    };

    public static EntityDesc[] SupplierDefine = {
            new EntityDesc("Name","Name","名称",0,true,String.class),
            new EntityDesc("Tel","Tel","电话",1,true,String.class),
            new EntityDesc("Address","Address","地址",2,true,String.class)
    };

    public static EntityDesc[] FoodProductDefine = {
            new EntityDesc("MealsTypeName","MealsTypeName","餐别",0,false,String.class),
            new EntityDesc("RecipeTemplateName","RecipeTemplateName","菜名",1,false,String.class),
            new EntityDesc("RecipeAmount","RecipeAmount","份数",2,false,Integer.class),
            new EntityDesc("TotalWeight","TotalWeight","总重",3,false,Integer.class),
            new EntityDesc("FoodMaterialName","FoodMaterialName","食材",4,false,String.class),
            new EntityDesc("FoodMaterialAmount","FoodMaterialAmount","食材量",5,false,Integer.class)
    };

}
